﻿namespace ProblemsSet
{
    public class Problem_39 : BaseProblem
    {
        public override object GetResult()
        {
            const int max = 1000;

            var mx = 0;
            var mxP = 0;

            for (var p = 1; p <= max; p++)
            {
                var cnt = 0;
                for (var a = 1; a < p/2; a++)
                {
                    for (var b = a; b < p/2; b++)
                    {
                        var c = p - a - b;
                        if (c * c == a * a + b * b) cnt++;
                    }
                }
                if (cnt > mx)
                {
                    mx = cnt;
                    mxP = p;
                }
            }
            return mxP;
        }

        public override string Problem
        {
            get
            {
                return @"If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p  1000, is the number of solutions maximised?";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 840;
            }
        }

    }
}
